package com.shop2cn.iapi.agentproducts.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.BatchUpdatePriceBean;
import com.shop2cn.iapi.agentproducts.parameter.ImportAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ModifyAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.OpenUpdatePriceDto;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.shop2cn.iapi.agentproducts.service.BatchUpdatePriceCall;
import com.ymatou.iapi.prodstock.parameter.AgentProductPo;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.AgentUsers;

/**
 * 批量更新商品价格 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_BatchUpdatePrice {
	private static BatchUpdatePriceBean batchupdatepriceBean;
	private static BatchUpdatePriceCall batchupdatepriceCall;
	private static YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
	private static YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();

	// vip渠道
	private static int vipRootUserId = AgentUsers.vipRootUserId;
	private static String vipRootUserName = "NickautoTest";
	private static int csId = AgentUsers.csId;
	// vip渠道->代理
	private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
	private static String vipAgentUserName1 = "dgsq408897016";
	private static int csId1 = AgentUsers.csId1;
	// vip渠道->代理->代理
	private static int vipAgentUserId2 = AgentUsers.vipAgentUserId2;
	private static String vipAgentUserName2 = "NickautoTest";

	// 渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	private static String rootUserName = "NickautoTest";
	// 渠道商->代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	private static String agentUserName1 = "NickautoTest";
	// 渠道商->代理商2
	private static int agentUserId2 = AgentUsers.agentUserId2;
	private static String agentUserName2 = "NickautoTest";

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量更新商品价格");
	}

	@Before
	public void caseUp() {
		batchupdatepriceBean = new BatchUpdatePriceBean();
		batchupdatepriceCall = new BatchUpdatePriceCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(batchupdatepriceCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_01() {
		Logger.start(true, "根据商品sku更新商品价格，更新成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
			openUpdatePriceDto.setOuterSku(addAgentProductBean.getCatalogList().get(0).getSku());
			BigDecimal price = new BigDecimal(300.000);
			openUpdatePriceDto.setSalePrice(price);
			updatePriceList.add(openUpdatePriceDto);
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(rootUserId);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			List<Map> cmap = ymtCatalogsIWapper.selectProductIdBySku(openUpdatePriceDto.getOuterSku());
			cmap.forEach(p -> {
				Logger.verifyEquals(price.doubleValue(), Double.valueOf(p.get("fQuotePrice").toString()), "验证商品价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_02() {
		Logger.start(true, "根据商品规格id更新商品价格，更新成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			BigDecimal price = new BigDecimal(300.000);
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
				openUpdatePriceDto.setCatalogId(p.getsCatalogId());
				openUpdatePriceDto.setSalePrice(price);
				updatePriceList.add(openUpdatePriceDto);
			});
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(rootUserId);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				Logger.verifyEquals(price.doubleValue(), p.getfQuotePrice().doubleValue(), "验证商品价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_03() {
		Logger.start(true, "代理商品更新价小于进货价，更新失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService
					.initImportAgentProduct(agentUserId1, agentUserName1, productId, rootUserId, false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			BigDecimal price = new BigDecimal(
					addAgentProductBean.getCatalogList().get(0).getAgentPriceList().get(0).getAgentPrice() - 100);
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(p -> {
				OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
				openUpdatePriceDto.setCatalogId(p.getsCatalogId());
				openUpdatePriceDto.setSalePrice(price);
				updatePriceList.add(openUpdatePriceDto);
			});
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(agentUserId1);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(p -> {
				// 价格没有更新
				Logger.verifyEquals(true, p.getfQuotePrice().doubleValue() != price.doubleValue(), "验证商品价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_04() {
		Logger.start(true, "userId为空，更新失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			BigDecimal price = new BigDecimal(300.000);
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
				openUpdatePriceDto.setCatalogId(p.getsCatalogId());
				openUpdatePriceDto.setSalePrice(price);
				updatePriceList.add(openUpdatePriceDto);
			});
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(0);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("400", batchupdatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				// 价格没有更新
				Logger.verifyEquals(true, p.getfQuotePrice().doubleValue() != price.doubleValue(), "验证商品价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_05() {
		Logger.start(true, "无效的catalogId，更新失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService
					.initImportAgentProduct(agentUserId1, agentUserName1, productId, rootUserId, false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			BigDecimal price = new BigDecimal(300.000);
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(p -> {
				OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
				openUpdatePriceDto.setCatalogId(p.getsCatalogId() + 1);
				openUpdatePriceDto.setSalePrice(price);
				updatePriceList.add(openUpdatePriceDto);
			});
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(0);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("400", batchupdatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(p -> {
				// 价格没有更新
				Logger.verifyEquals(true, p.getfQuotePrice().doubleValue() != price.doubleValue(), "验证商品价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_06() {
		Logger.start(true, "无效的sku，更新失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
			openUpdatePriceDto.setOuterSku(addAgentProductBean.getCatalogList().get(0).getSku() + 100);
			BigDecimal price = new BigDecimal(300.000);

			openUpdatePriceDto.setSalePrice(price);
			updatePriceList.add(openUpdatePriceDto);
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(rootUserId);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				// 价格没有更新
				Logger.verifyEquals(true, p.getfQuotePrice().doubleValue() != price.doubleValue(), "验证商品价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_07() {
		Logger.start(true, "更新的价格为负数，更新失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
			openUpdatePriceDto.setOuterSku(addAgentProductBean.getCatalogList().get(0).getSku());
			BigDecimal price = new BigDecimal(-300.000);
			openUpdatePriceDto.setSalePrice(price);
			updatePriceList.add(openUpdatePriceDto);
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(rootUserId);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				// 价格没有更新
				Logger.verifyEquals(true, p.getfQuotePrice().doubleValue() != price.doubleValue(), "验证商品价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_08() {
		Logger.start(true, "更新的价格小数点后多于两位，更新失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
			openUpdatePriceDto.setOuterSku(addAgentProductBean.getCatalogList().get(0).getSku());
			BigDecimal price = new BigDecimal(300.011);
			openUpdatePriceDto.setSalePrice(price);
			updatePriceList.add(openUpdatePriceDto);
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(rootUserId);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				// 价格没有更新
				Logger.verifyEquals(true, p.getfQuotePrice().doubleValue() != price.doubleValue(), "验证商品价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_09() {
		Logger.start(true, "skuId和catalogId为空，更新失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
			BigDecimal price = new BigDecimal(300);
			openUpdatePriceDto.setSalePrice(price);
			updatePriceList.add(openUpdatePriceDto);
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(rootUserId);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				// 价格没有更新
				Logger.verifyEquals(true, p.getfQuotePrice().doubleValue() != price.doubleValue(), "验证商品价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_10() {
		Logger.start(true, "同时传入sku和catalogId，以catalogId为准，更新成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			BigDecimal price = new BigDecimal(300);
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
				openUpdatePriceDto.setCatalogId(p.getsCatalogId());
				openUpdatePriceDto.setSalePrice(price);
				openUpdatePriceDto.setOuterSku("11");
				updatePriceList.add(openUpdatePriceDto);
			});
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(rootUserId);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				Logger.verifyEquals(price.doubleValue(), p.getfQuotePrice().doubleValue(), "验证商品价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_11() {
		Logger.start(true, "普通代理商更新商品价格，修改后的直销价小于拿到的进货价,更新失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService
					.initImportAgentProduct(agentUserId1, agentUserName1, productId, rootUserId, false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			BigDecimal price = new BigDecimal(100);
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(p -> {
				OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
				openUpdatePriceDto.setCatalogId(p.getsCatalogId());
				openUpdatePriceDto.setSalePrice(price);
				updatePriceList.add(openUpdatePriceDto);
			});
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(agentUserId1);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			// 价格没变
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(p -> {
				Logger.verifyEquals(true, p.getfQuotePrice().doubleValue() != price.doubleValue(), "验证商品价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_12() {
		Logger.start(true, "普通代理商更新商品价格，上级未设置代理价,修改后的直销价小于上级的原价,更新失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService
					.initImportAgentProduct(agentUserId1, agentUserName1, productId, rootUserId, false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			BigDecimal price = new BigDecimal(80);
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(p -> {
				OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
				openUpdatePriceDto.setCatalogId(p.getsCatalogId());
				openUpdatePriceDto.setSalePrice(price);
				updatePriceList.add(openUpdatePriceDto);
			});
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(agentUserId1);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			// 价格没变
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(p -> {
				Logger.verifyEquals(true, p.getfQuotePrice().doubleValue() != price.doubleValue(), "验证商品价格");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_13() {
		Logger.start(true, "上下级sku不一致时，上级根据商品sku更新商品价格，更新成功");
		try {

			// 渠道商新建商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,
					vipRootUserName, true);
			int rootsku1 = Integer.parseInt(addAgentProductBean.getCatalogList().get(0).getSku());
			int rootsku2 = Integer.parseInt(addAgentProductBean.getCatalogList().get(0).getSku());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);

			// vip1代理渠道商
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService
					.initImportAgentProduct(vipAgentUserId1, vipAgentUserName1, productId, vipRootUserId, true);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			// VIP2代理vip1
			ImportAgentProductBean importAgentProductBean1 = AddAgentProductCallService
					.initImportAgentProduct(vipAgentUserId2, vipAgentUserName2, agentProductId, vipAgentUserId1, false);
			String agentProductId1 = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean1);

			// 修改vip1的sku
			ModifyAgentProductBean mpb = AddAgentProductCallService
					.initModifyAgentProductBeanByImportant(agentProductId, importAgentProductBean);
			mpb.getCatalogList().get(0).setSku("666666");
			AddAgentProductCallService.modifyAgentProduct(mpb);

			// 修改vip2的sku
			ModifyAgentProductBean mpb1 = AddAgentProductCallService
					.initModifyAgentProductBeanByImportant(agentProductId1, importAgentProductBean1);
			mpb1.getCatalogList().get(0).setSku("888888");
			AddAgentProductCallService.modifyAgentProduct(mpb1);

			// 渠道商添加双拼
			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
			openUpdatePriceDto.setOuterSku(addAgentProductBean.getCatalogList().get(0).getSku());
			BigDecimal price = new BigDecimal(300.000);
			openUpdatePriceDto.setSalePrice(price);
			updatePriceList.add(openUpdatePriceDto);
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(vipRootUserId);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			List<Map> cmap = ymtCatalogsIWapper.selectProductIdBySku(openUpdatePriceDto.getOuterSku());
			cmap.forEach(p -> {
				Logger.verifyEquals(price.doubleValue(), Double.valueOf(p.get("fQuotePrice").toString()), "验证商品价格");
				System.out.println(Double.valueOf(p.get("fQuotePrice").toString()));
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_014() {
		Logger.start(true, "代理商修改，撤销自动加价的标");
		try {
			int rootUserId = 501475646;
			int agentUserId = 501475647;
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId, "",
					true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			// 查到代理商的商品id
			List<AgentProductPo> ap = ymtProductsIWapper.selectAgentProductByRootProductId(productId).stream()
					.filter(x -> x.getAction() == 0).filter(x -> x.getUserId() == agentUserId)
					.collect(Collectors.toList());
			Logger.debug("ap:" + FormatUtil.beanToGSONString(ap));
			String agentProductId = ap.get(0).getProductId();

			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			BigDecimal price = new BigDecimal(350.000);
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(p -> {
				OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
				openUpdatePriceDto.setCatalogId(p.getsCatalogId());
				openUpdatePriceDto.setSalePrice(price);
				updatePriceList.add(openUpdatePriceDto);
			});
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(agentUserId);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(agentProductId).forEach(p -> {
				Logger.verifyEquals(price.doubleValue(), p.getfQuotePrice().doubleValue(), "验证商品价格");
			});

			ProductDetailsDto agentProd = AddAgentProductCallService.selectProductDetails(agentUserId, agentProductId);

			// 商品打标
			Logger.verifyEquals(agentProd.getAutoMarkupStatus(), 0, "没有了自动加价的标");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_BatchUpdatePrice_015() {
		Logger.start(true, "渠道商修改商品价格--发送总线--验证使用直销价的代理商的价格");
		try {
			
			int rootUserId = 500777216;
			int agentUserId = 500777217;
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId, "",
					true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(15000);
			// 查到代理商的商品id
			List<AgentProductPo> ap = ymtProductsIWapper.selectAgentProductByRootProductId(productId).stream()
					.filter(x -> x.getAction() == 0).filter(x -> x.getUserId() == agentUserId)
					.collect(Collectors.toList());
			Logger.debug("ap:" + FormatUtil.beanToGSONString(ap));
			String agentProductId = ap.get(0).getProductId();
			

			List<OpenUpdatePriceDto> updatePriceList = new ArrayList<>();
			BigDecimal price = new BigDecimal(350.000);
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				OpenUpdatePriceDto openUpdatePriceDto = new OpenUpdatePriceDto();
				openUpdatePriceDto.setCatalogId(p.getsCatalogId());
				openUpdatePriceDto.setSalePrice(price);
				updatePriceList.add(openUpdatePriceDto);
			});
			batchupdatepriceBean.setUpdatePriceList(updatePriceList);
			batchupdatepriceBean.setUserId(rootUserId);
			batchupdatepriceCall.setData(batchupdatepriceBean);
			batchupdatepriceCall.callService();
			Logger.verifyEquals("200", batchupdatepriceCall.getString("code"), "验证code");
			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(p -> {
				Logger.verifyEquals(price.doubleValue(), p.getfQuotePrice().doubleValue(), "验证商品价格");
			});

			// 验证总线消息
			MessageListBean MessageListBean = MqQueryCallService.initSyncAutoMarkup(agentProductId, agentUserId);
			List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			System.out.println(MessageListBean.toString());
			if (joa.size() == 0) {
				Thread.sleep(5000);
				joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			Logger.verifyEquals(joa.size(), 1, "有更新价格的总线消息");
			joa.forEach(ele -> {
				Logger.debug(ele.toString());
			});
			Thread.sleep(5000);
			ProductDetailsDto agentProd = AddAgentProductCallService.selectProductDetails(agentUserId, agentProductId);
			ProductDetailsDto rootProd = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			Logger.verifyEquals(350.00,
					agentProd.getCatalogList().get(0).getDirectPrice(), "验证代理商与渠道商的直销价一致");
			// 代理价=直销价
			Logger.verifyEquals(rootProd.getCatalogList().get(0).getDirectPrice(),
					agentProd.getCatalogList().get(0).getDirectPrice(), "验证代理商与渠道商的直销价一致");
			// 商品打标
			Logger.verifyEquals(agentProd.getAutoMarkupStatus(), 1, "已经被打上自动加价的标");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}